package com.zjw.zy.utils;

import static android.widget.LinearLayout.VERTICAL;

import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import androidx.annotation.IdRes;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.zjw.zy.MainActivity;
import com.zjw.zy.R;
import com.zjw.zy.smi.JustWithIt;

/**
 * @author ：zhong.jw
 * @date ：Created in 2022/9/29 8:52
 */
public final class WindowUtils {

    private static final String TAG = "WindowUtils";

    private static Rect sScreen;

    public static void init(@NonNull MainActivity mainActivity) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            sScreen = mainActivity.getWindowManager().getMaximumWindowMetrics().getBounds();
        } else {
            sScreen = new Rect();
            sScreen.bottom = mainActivity.getWindowManager().getDefaultDisplay().getHeight();
            sScreen.right = mainActivity.getWindowManager().getDefaultDisplay().getWidth();
        }
    }

    public static int getScreenWidth() {
        return sScreen.right - sScreen.left;
    }

    public static int getScreenHeight() {
        return sScreen.bottom - sScreen.top;
    }

    public static Rect getScreen() {
        return sScreen;
    }

    public static void fullMode() {
        TopBar.hide();
        FootBar.hide();
        AppUtils.getMainActivity().transparentStatusBar();
    }

    public static final class FootBar {
        public static void hide() {
            AppUtils.getMainActivity().footBar().setVisibility(View.GONE);
        }

        public static void show() {
            AppUtils.getMainActivity().footBar().setVisibility(View.VISIBLE);
        }
    }

    public static final class PopupWindow {

        private static android.widget.PopupWindow popupWindow;

        public static View show(View author, @LayoutRes int layoutId, int width, int height) {
            View inflate = LayoutInflater.from(author.getContext()).inflate(layoutId, null);
            popupWindow = new android.widget.PopupWindow(inflate, width, height);
            popupWindow.showAsDropDown(author);

            return inflate;
        }

        public static void hide() {
            if (popupWindow != null) {
                popupWindow.dismiss();
                popupWindow = null;
            }
        }
    }

    public static final class TopBar {

        public static void hide() {
            AppUtils.getMainActivity().topBar().setVisibility(View.GONE);
        }

        public static void show() {
            AppUtils.getMainActivity().topBar().setVisibility(View.VISIBLE);
        }

        public static void showBack() {
            show();
            AppUtils.getMainActivity().topBar().showBackButton();
        }

        public static void hideBack() {
            AppUtils.getMainActivity().topBar().hideBackButton();
        }


        public static void showTopBarNav() {
            show();
            AppUtils.getMainActivity().topBar().showNavButton();
        }

        public static void hideNav() {
            AppUtils.getMainActivity().topBar().hideNavButton();
        }

        public static void setTopBarLabelText(@NonNull String text) {
            AppUtils.getMainActivity().topBar().setLabelText(text);
        }

        public static void show1RightButton(@NonNull Drawable image, @Nullable View.OnClickListener listener) {
            AppUtils.getMainActivity().topBar().show1RightButton(image, listener);
            AppUtils.getMainActivity().topBar().setEnableRightButton(true);
        }

        public static void show2RightButton(@NonNull Drawable image, @Nullable View.OnClickListener listener) {
            AppUtils.getMainActivity().topBar().show2RightButton(image, listener);
            AppUtils.getMainActivity().topBar().setEnable2RightButton(true);
        }

        public static void show3RightButton(@NonNull Drawable image, @Nullable View.OnClickListener listener) {
            AppUtils.getMainActivity().topBar().show3RightButton(image, listener);
            AppUtils.getMainActivity().topBar().setEnable3RightButton(true);
        }

        public static void show4RightButton(@NonNull Drawable image, @Nullable View.OnClickListener listener) {
            AppUtils.getMainActivity().topBar().show4RightButton(image, listener);
            AppUtils.getMainActivity().topBar().setEnable4RightButton(true);
        }


        public static void update1RightButton(@NonNull Drawable image) {
            AppUtils.getMainActivity().topBar().update1RightButton(image);
        }

        public static void update2RightButton(@NonNull Drawable image) {
            AppUtils.getMainActivity().topBar().update2RightButton(image);
            AppUtils.getMainActivity().topBar().setEnable2RightButton(true);
        }

        public static void update3RightButton(@NonNull Drawable image) {
            AppUtils.getMainActivity().topBar().update3RightButton(image);
            AppUtils.getMainActivity().topBar().setEnable3RightButton(true);
        }

        public static void update4RightButton(@NonNull Drawable image) {
            AppUtils.getMainActivity().topBar().update4RightButton(image);
            AppUtils.getMainActivity().topBar().setEnable3RightButton(true);
        }

        public static void hideRightButton() {
            AppUtils.getMainActivity().topBar().hideRightButton();
        }

        public static void hide2RightButton() {
            AppUtils.getMainActivity().topBar().hide2RightButton();
        }

        public static void hide3RightButton() {
            AppUtils.getMainActivity().topBar().hide3RightButton();
        }

        public static void hide4RightButton() {
            AppUtils.getMainActivity().topBar().hide4RightButton();
        }

        public static void setEnableRightButton(boolean enable) {
            AppUtils.getMainActivity().topBar().setEnableRightButton(enable);
        }

        public static void setEnable2RightButton(boolean enable) {
            AppUtils.getMainActivity().topBar().setEnable2RightButton(enable);
        }

        public static void setEnable3RightButton(boolean enable) {
            AppUtils.getMainActivity().topBar().setEnable3RightButton(enable);
        }

        public static void setEnable4RightButton(boolean enable) {
            AppUtils.getMainActivity().topBar().setEnable4RightButton(enable);
        }

        public static void hideAllRightButton() {
            hideRightButton();
            hide2RightButton();
            hide3RightButton();
            hide4RightButton();
        }
    }
}
